# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=HTF
pkgname=haskell-htf
pkgver=0.15.0.1
pkgrel=43
pkgdesc="The Haskell Test Framework"
url="https://github.com/skogsbaer/HTF/"
license=("LGPL2")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-diff' 'haskell-hunit' 'haskell-quickcheck' 'haskell-aeson'
         'haskell-base64-bytestring' 'haskell-cpphs' 'haskell-src' 'haskell-lifted-base'
         'haskell-monad-control' 'haskell-old-time' 'haskell-random' 'haskell-regex-compat'
         'haskell-vector' 'haskell-xmlgen')
makedepends=('ghc' 'haskell-aeson-pretty' 'haskell-temporary' 'haskell-unordered-containers')
source=("https://hackage.haskell.org/packages/archive/$_hkgname/$pkgver/$_hkgname-$pkgver.tar.gz")
sha256sums=('bc16a958bd36b03f673388470eed7fea01daaa1604677bb08dfb910598d39856')

build() {
  cd $_hkgname-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie'

  LD_LIBRARY_PATH="$PWD"/dist/build runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
  cd $_hkgname-$pkgver
  # https://github.com/skogsbaer/HTF/issues/123
  runhaskell Setup test --show-details=direct || echo "Tests failed"
}

package() {
  cd $_hkgname-$pkgver

  install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
  install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
